package com.aoyama.collection.arraylist.v2;

/**
 * <p>
 *
 * </p>
 *
 * @author qingshan
 * @since 2021/4/1 2:06 下午
 */
public class LinkedList_<E> implements List_<E> {

    private int size;

    /**
     *
     */
    Node first;

    Node last;

    /**
     * 静态内部类
     */
    private static class Node<E> {
        E element;
        Node<E> prev;
        Node<E> next;

        public Node(Node prev, E element, Node next) {
            this.element = element;
            this.prev = prev;
            this.next = next;
        }
    }

    @Override
    public int size() {
        return size;
    }

    @Override
    public boolean isEmpty() {
        return size == 0;
    }

    @Override
    public boolean add(E e) {
        // 链表结构， 不存在需要扩容问题
        Node<E> l = last;
        Node<E> newNode = new Node<E>(last, e, null);
        last = newNode;
        if (l == null) { // true elementsData为空
            first = newNode;
        } else {
            l.next = newNode;
        }
        size ++;
        return true;
    }

    @Override
    public boolean addAll(Object[] objects) {
        return false;
    }

    @Override
    public boolean contain(E e) {
        return false;
    }

    /**
     * 迭代器
     * @return
     */
    @Override
    public Iterator_<E> iterator() {

        return null;
    }
}
